package com.tzbank.back.service.impl;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.tzbank.back.dao.AuthModuleMapper;
import com.tzbank.back.service.AuthModuleService;
import com.tzbank.entity.backstage.AuthModule;
import com.tzbank.utils.CodeUtil;
import com.tzbank.utils.ResultUtil;

@Service
public class AuthModuleServiceImpl implements AuthModuleService {

	@Autowired
	private AuthModuleMapper authModuleMapper;

	@Transactional
	@Override
	public Map<String, Object> deleteAuthModule(AuthModule authModule) throws Exception{
		this.authModuleMapper.deleteAuthModule(authModule);
		return ResultUtil.resultMap(CodeUtil.CODE_200.getName(), CodeUtil.CODE_200.getCode(), null);
	}

	@Transactional
	@Override
	public Map<String, Object> insertAuthModule(AuthModule authModule) throws Exception{
		authModule.setCreateDate(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
		authModule.setUpdateDate(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
		this.authModuleMapper.insertAuthModule(authModule);
		return ResultUtil.resultMap(CodeUtil.CODE_200.getName(), CodeUtil.CODE_200.getCode(), null);
	}

	@Override
	public Map<String, Object> selectAuthModuleByAutoId(int autoId) throws Exception{
		AuthModule authModule = this.authModuleMapper.selectAuthModuleByAutoId(autoId);
		return ResultUtil.resultMap(CodeUtil.CODE_200.getName(), CodeUtil.CODE_200.getCode(), authModule);
	}

	@Override
	public Map<String, Object> selectAuthModule() throws Exception{
		List<AuthModule> authModules = this.authModuleMapper.selectAuthModule();
		return ResultUtil.resultMap(CodeUtil.CODE_200.getName(), CodeUtil.CODE_200.getCode(), authModules);
	}

	@Override
	public Map<String, Object> updateAuthModule(AuthModule authModule) throws Exception{
		authModule.setUpdateDate(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
		this.authModuleMapper.updateAuthModule(authModule);
		return ResultUtil.resultMap(CodeUtil.CODE_200.getName(), CodeUtil.CODE_200.getCode(), null);
	}

}
